#pragma once

#include "locallock.hpp"

int count7 = 100;
My_local_lock::LocalLockLinux mymutex7;

void *thread7(void *argv)
{
    while (1)
    {
        My_local_lock::LockGuard mylocks(mymutex7);
        if (count7 > 0)
        {
            usleep(1000);
            std::cout << "child thread tid: " << (char *)argv << " my count = " << count7 << std::endl;
            count7--;
        }
        else
        {
            return nullptr;
        }
    }
    return nullptr;
}

// linux加锁
void linux_mutex_struct_RAII()
{
    pthread_t pth1_id;
    int pth1_ret = pthread_create(&pth1_id, NULL, thread7, (void *)"string1_name");
    pthread_t pth2_id;
    int pth2_ret = pthread_create(&pth2_id, NULL, thread7, (void *)"string2_name");
    pthread_t pth3_id;
    int pth3_ret = pthread_create(&pth3_id, NULL, thread7, (void *)"string3_name");
    pthread_t pth4_id;
    int pth4_ret = pthread_create(&pth4_id, NULL, thread7, (void *)"string4_name");
    pthread_t pth5_id;
    int pth5_ret = pthread_create(&pth5_id, NULL, thread7, (void *)"string5_name");

    pthread_detach(pth1_id);
    pthread_detach(pth2_id);
    pthread_detach(pth3_id);
    pthread_detach(pth4_id);
    pthread_detach(pth5_id);

    while (count7 > 0)
    {
        usleep(1000);
    }
    usleep(2000);
}
